package bb.lanxing.network;

import bb.lanxing.App;
import bb.lanxing.util.NetworkUtil;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import okhttp3.CacheControl;
import okhttp3.Interceptor;

public class BiciCacheControl implements Interceptor {
    @Override
    public okhttp3.Response intercept(Interceptor.Chain chain) throws IOException {
        CacheControl.Builder builder = new CacheControl.Builder();
        if (!NetworkUtil.isWifiConnected() && !NetworkUtil.isMobileConnected() && NetworkUtil.getConnectedType(App.getContext()) == -1) {
            builder.maxStale(Integer.MAX_VALUE, TimeUnit.SECONDS);
            builder.onlyIfCached();
        }
        return chain.proceed(chain.request().newBuilder().cacheControl(builder.build()).build());
    }
}
